//
//  ColorPickViewController.m
//  CarTown
//
//  Created by xionghao on 15/8/10.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "ColorPickViewController.h"
#import "MultLineRadioGroup.h"
#import "ColorResdMode.h"
#import "ColorModel.h"
@interface ColorPickViewController ()<UITextFieldDelegate,MultlineRadioGroupDelegate>
@property (weak, nonatomic) IBOutlet MultLineRadioGroup *multlinegroup;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *radiogroupheight;
@property (weak, nonatomic) IBOutlet UITextField *colorinput;

@end

@implementation ColorPickViewController
+(instancetype)colorpicker{
    ColorPickViewController *cpvc=[[ColorPickViewController alloc]initWithNibName:@"ColorPickViewController" bundle:nil];
    return cpvc;
}

-(void)radioclick{
     self.colorinput.text=@"";
    if ([_delegate respondsToSelector:@selector(ColorPikcerClickContoller:withIndex:ColorStr:)]) {
   
        [_delegate ColorPikcerClickContoller:self withIndex:self.multlinegroup.selectedIndex ColorStr:self.multlinegroup.titlesarray[self.multlinegroup.selectedIndex]];
        
        
    }
    [self.navigationController popViewControllerAnimated:YES];

    [self.colorinput endEditing:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setupview];
    self.multlinegroup.delegate=self;
    
    self.colorinput.delegate=self;
    self.navigationItem.title=@"外观颜色";
   
    
}
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if ([_delegate respondsToSelector:@selector(ColorPikcerClickContoller:withIndex:ColorStr:)]) {
        if (self.colorinput.text.length>0) {
            [_delegate ColorPikcerClickContoller:self withIndex:-1 ColorStr:self.colorinput.text];
        }
        
    }
    [textField endEditing:YES];
    [self.navigationController popViewControllerAnimated:YES];
    
    return YES;
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    self.multlinegroup.selectedIndex=-1;
    
    return YES;
}
-(void)setupview{
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    
    if (self.isOut) {
        params[@"action"]=@"out";
    }else{
        params[@"action"]=@"in";
    }
    params[@"mid"]=self.ID;
    
    [PostUitls Post:colorUrl parameters:params success:^(id response) {
        ColorResdMode *resdmode=[ColorResdMode resdWithDict:response];
        NSMutableArray *marray=[NSMutableArray array];
        if (resdmode.data.count>0) {
            
            
            for (ColorModel *mode in resdmode.data) {
                [marray addObject:mode.name];
            }
            int rows=(marray.count/4)+1;
            self.radiogroupheight.constant=(27+8)*rows+8;
            self.multlinegroup.titlesarray=marray;
            self.multlinegroup.selectedIndex=self.index;
            if (self.index==-1) {
                self.colorinput.text=self.colorstr;
            }
        }else{
            self.radiogroupheight.constant=0;
        }
    } failure:^(NSError *error) {
         self.radiogroupheight.constant=0;
    }];
    
}
-(void)rightclick{
    
    }
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
